import json

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from tortoise.contrib.fastapi import register_tortoise
from orm.stu_model import Student
from uvicorn import run
from settings import TORTOISE_ORM

app = FastAPI()
register_tortoise(app=app, config=TORTOISE_ORM)
app.mount("/static", StaticFiles(directory='static'))


@app.get("/")
async def root():
    return {"message": "Hello World"}


# @app.get("/hello/{name}")
# async def say_hello(name: str):
#     return {"message": f"Hello {name}"}


@app.get("/hello/stu")
async def student():
    students = await Student.all()

    for s in students:
        print(s.name)

    return students


if __name__ == '__main__':
    run(app, host='127.0.0.1', port=9200)